package com.tssup.fesco.common.frame.common;


import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

@JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
public class WeixinWebApiResult {

    private final static String SUCCESS_CODE = "0";
    private final static String SUCCESS_MSG = "success";

    private final static WeixinWebApiResult SUCCESS_WITH_NO_RESULT = new WeixinWebApiResult(SUCCESS_MSG, SUCCESS_CODE);

    private String code;
    private String msg;
    private Object data;

    public WeixinWebApiResult() {
    }

    public WeixinWebApiResult(Object data) {
        this.code = SUCCESS_CODE;
        this.msg = SUCCESS_MSG;
        this.data = data;
    }

    public WeixinWebApiResult(String msg, String code) {
        this.msg = msg;
        this.code = code;
    }

    public WeixinWebApiResult(String code, String msg, Object data) {
    	this.msg = msg;
    	this.code = code;
        this.data = data;
    }

    public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	/**
     * 创建一个成功的返回, 但不需要返回空数据。
     *
     * @return
     */
    public static WeixinWebApiResult success() {
        return SUCCESS_WITH_NO_RESULT;
    }

    /**
     * 创建一个成功的返回, 并返回指定的数据。
     *
     * @return
     */
    public static WeixinWebApiResult success(Object data) {
        WeixinWebApiResult result = new WeixinWebApiResult(SUCCESS_MSG, SUCCESS_CODE);
        result.setData(data);
        return result;
    }

    /**
     * 创建一个失败的返回。
     *
     * @return
     */
    public static WeixinWebApiResult failure(String errCode, String errMsg) {
        return new WeixinWebApiResult(errMsg, errCode);
    }

    /**
     * 创建一个失败的返回, 同时返回数据。
     *
     * @return
     */
    public static WeixinWebApiResult failure(String errCode, String errMsg, Object object) {
        return new WeixinWebApiResult(errCode, errMsg, object);
    }

}
